package mnc.game.tifo;

import java.util.ArrayList;

import bayaba.engine.lib.ButtonObject;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

public class GLView extends GLSurfaceView
{
	Context mContext;	
	public GameMain sImg;
	private int moveCount = 0;

	public GLView( Context context, GameMain img )
	{
		super( context );
		setFocusable( true );
		
		mContext = context;
		sImg = img;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event)
    {
		final int action = event.getAction();
		
		synchronized ( sImg.mGL )
		{
			sImg.TouchX = event.getX() * sImg.gInfo.ScalePx;
			sImg.TouchY = event.getY() * sImg.gInfo.ScalePy;
			
			switch ( action & MotionEvent.ACTION_MASK )
			{
			
				case	MotionEvent.ACTION_DOWN	:
						{
							sImg.gInfo.ListViewActionDown( sImg.TouchX, sImg.TouchY );	
						}
				case	MotionEvent.ACTION_MOVE :
						{ 
							System.out.println(sImg.OldX + " ... " + sImg.OldY + " ||| " +sImg.TouchX + " >> move >> " + sImg.TouchY + " ... " + Math.abs(sImg.OldX - sImg.TouchX) + " >> "+ Math.abs(sImg.OldY - sImg.TouchY) );

//							if( Math.abs(sImg.OldX - sImg.TouchX) > 15 || Math.abs(sImg.OldY - sImg.TouchY) > 15 )  sImg.slideYn = 1;
//							if(moveCount > 4) { sImg.slideYn = 1; } else { sImg.slideYn = 0; }

							sImg.gInfo.ListViewActionMove( sImg.TouchX, sImg.TouchY );
						}
				case	MotionEvent.ACTION_POINTER_DOWN	:
						{
							
							if(sImg.FirstValChk == 0) {
								sImg.OldX = sImg.TouchX;
								sImg.OldY = sImg.TouchY;
								sImg.FirstValChk = 1;
								moveCount = 0;
							} 
//							System.out.println("OldX = " + sImg.OldX + " >>> OldY = " + sImg.OldY);
							sImg.PushButton( true );
						}
						break;
		
				case	MotionEvent.ACTION_UP :
				case	MotionEvent.ACTION_POINTER_UP :
						{
//							sImg.gInfo.ScrollListView( sImg.CurLayer, 200, sImg.TouchX, sImg.TouchY, sImg.Button );
							if(sImg.GameMode == 91) {  // 친구순위
								sImg.gInfo.ScrollListView( sImg.FriendRankingUI.CurrentLayer, 300, sImg.TouchX, sImg.TouchY, sImg.FriendRankingUI.UIList );
							} else if(sImg.GameMode == 92) {  // 환경설정 
								sImg.gInfo.ScrollListView( sImg.SettingUI.CurrentLayer, 300, sImg.TouchX, sImg.TouchY, sImg.SettingUI.UIList );
							} else if(sImg.GameMode == 93) {  // 친구초대 
								sImg.gInfo.ScrollListView( sImg.Friend_InVitUI.CurrentLayer, 300, sImg.TouchX, sImg.TouchY, sImg.Friend_InVitUI.UIList );
							} else if(sImg.GameMode == 94) {  // 상점  
								sImg.gInfo.ScrollListView( sImg.TimeBuyUI.CurrentLayer, 300, sImg.TouchX, sImg.TouchY, sImg.TimeBuyUI.UIList );
							} else if(sImg.GameMode == 90) {  // 공지사항  
								sImg.gInfo.ScrollListView( sImg.NoticeUI.CurrentLayer, 300, sImg.TouchX, sImg.TouchY, sImg.NoticeUI.UIList );
							}
							sImg.FirstValChk = 0; 
							sImg.PushButton( false );
						}
						break;
			}
		}
      	return true;
    }

}
